home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
doorIndoor.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
4KB
|
153 lines
-- door state machine
DOORBEHAVIOR = "doorBehaviour";
DOORBEHAVIOR_AUTO = nil;
DOORBEHAVIOR_ALWAYS_OPEN = "open";
DOORBEHAVIOR_ALWAYS_CLOSED = "closed";
beginStateMachine()
onEnter(function(msg)
this.getGameObjectServer().scanApartment();
if (isBathroomDoor(this)) then
setState("closed")
else
setState("openLeft")
end
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_AUTO);
end )
state("closed")
onEnter(function(msg)
setWalkability(0);
end )
onMsg("openDoorLeft", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_OPEN);
end
setState("openLeft");
end )
onMsg("openDoorRight", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_OPEN);
end
setState("openRight");
end )
onMsg("buildMenu", function(msg)
-- build the pie menu
clearPieMenu();
local button ;
button = addPieMenuButton("pm_open", "openDoorLeft");
button.addDescription(USERACTION, "true");
end )
state("openLeft")
onEnter(function(msg)
startAnimation("doorOpenLeft");
setWalkability(1)
playSound("doorOpenClose");
end )
onExit(function(msg)
startAnimation("doorCloseLeft");
end )
onMsg("closeDoorLeft", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
end
local doorBehavior = this.retrieveData(DOORBEHAVIOR);
if ((msg.sender == NO_OBJECT_ID)
or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
setState("closed");
end
end )
onMsg("closeDoorRight", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
end
local doorBehavior = this.retrieveData(DOORBEHAVIOR);
if ((msg.sender == NO_OBJECT_ID)
or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
setState("closed");
end
end )
onMsg("buildMenu", function(msg)
-- build the pie menu
clearPieMenu();
local button ;
button = addPieMenuButton("pm_close", "closeDoorLeft");
button.addDescription(USERACTION, "true");
end )
state("openRight")
onEnter(function(msg)
startAnimation("doorOpenRight");
setWalkability(2)
playSound("doorOpenClose");
end )
onExit(function(msg)
startAnimation("doorCloseRight");
end )
onMsg("closeDoorLeft", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
end
local doorBehavior = this.retrieveData(DOORBEHAVIOR);
if ((msg.sender == NO_OBJECT_ID)
or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
setState("closed");
end
end )
onMsg("closeDoorRight", function(msg)
if (msg.sender == NO_OBJECT_ID) then
this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
end
local doorBehavior = this.retrieveData(DOORBEHAVIOR);
if ((msg.sender == NO_OBJECT_ID)
or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
setState("closed");
end
end )
onMsg("buildMenu", function(msg)
-- build the pie menu
clearPieMenu();
local button ;
button = addPieMenuButton("pm_close", "closeDoorRight");
button.addDescription(USERACTION, "true");
end )
endStateMachine()